package com.vmware.elastic.index;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.GetIndexResponse;

/**
 * @apiNote 演示查询索引
 */
public class IndexQuery {
    public static void main(String[] args) throws Exception {
        RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(
                new HttpHost("10.192.193.98", 9200))
        );
        GetIndexRequest request = new GetIndexRequest("vmware");
        GetIndexResponse response = client.indices().get(request, RequestOptions.DEFAULT);
        System.out.println(response.getAliases());//获取别名
        //{vmware=[]}
        System.out.println(response.getMappings());//获取索引映射
        //{vmware=org.elasticsearch.cluster.metadata.MappingMetadata@9b2cfd3c}
        System.out.println(response.getSettings());//获取索引设置
        //{vmware={"index.creation_date":"1690635515922","index.number_of_replicas":"1","index.number_of_shards":"1","index.provided_name":"vmware","index.uuid":"HtIuUNNnTTyz9CT2oz0Lww","index.version.created":"7060299"}}
        client.close();
    }
}
